﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Bzure.Common.Events;
using Bzure.Common.HttpAspects.Configuration;

namespace Bzure.Common.HttpAspects
{

    public class HttpConifgBus : EventComponentBase<HttpEventOption,EventHandler >, IHttpModule
    {      
        public void Dispose()
        {
        }
        public void Init(HttpApplication context)
        {
            foreach (AspectConfig config in AspectBusConfig.Aspects)
            {
                config.GetAspectHandler().InitAspect(this);
            }

            context.BeginRequest += new EventHandler(context_BeginRequest);
            context.AuthenticateRequest += new EventHandler(context_AuthenticateRequest);
            context.PostAuthenticateRequest += new EventHandler(context_PostAuthenticateRequest);
            context.AuthorizeRequest += new EventHandler(context_AuthorizeRequest);
            context.PostAuthorizeRequest += new EventHandler(context_PostAuthorizeRequest);
            context.ResolveRequestCache += new EventHandler(context_ResolveRequestCache);
            context.PostResolveRequestCache += new EventHandler(context_PostResolveRequestCache);
            context.PostMapRequestHandler += new EventHandler(context_PostMapRequestHandler);
            context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
            context.PostAcquireRequestState += new EventHandler(context_PostAcquireRequestState);
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
            context.PostRequestHandlerExecute += new EventHandler(context_PostRequestHandlerExecute);
            context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
            context.PostReleaseRequestState += new EventHandler(context_PostReleaseRequestState);
            context.UpdateRequestCache += new EventHandler(context_UpdateRequestCache);
            context.PostUpdateRequestCache += new EventHandler(context_PostUpdateRequestCache);
            context.EndRequest += new EventHandler(context_EndRequest);
        }
        #region raise event
        void context_EndRequest(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.EndRequest, sender, e);
        }

        void context_PostUpdateRequestCache(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostUpdateRequestCache, sender, e);
        }

        void context_UpdateRequestCache(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.UpdateRequestCache, sender, e);
        }

        void context_PostReleaseRequestState(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostReleaseRequestState, sender, e);
        }

        void context_ReleaseRequestState(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.ReleaseRequestState, sender, e);
        }

        void context_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostRequestHandlerExecute, sender, e);
        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PreRequestHandlerExecute, sender, e);
        }

        void context_PostAcquireRequestState(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostAcquireRequestState, sender, e);
        }

        void context_AcquireRequestState(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.AcquireRequestState, sender, e);
        }

        void context_PostMapRequestHandler(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostMapRequestHandler, sender, e);
        }

        void context_PostResolveRequestCache(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostResolveRequestCache, sender, e);
        }

        void context_ResolveRequestCache(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.ResolveRequestCache, sender, e);
        }

        void context_PostAuthorizeRequest(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostAuthorizeRequest, sender, e);
        }

        void context_AuthorizeRequest(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.AuthorizeRequest, sender, e);
        }

        void context_PostAuthenticateRequest(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.PostAuthenticateRequest, sender, e);
        }

        void context_AuthenticateRequest(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.AuthenticateRequest, sender, e);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            this.RaiseEvent(HttpEventOption.BeginRequest, sender, e);
        }
        #endregion
    }
}
